<template>
  <div>
    <Form inline :label-colon="true" class="search-form" :label-width="80">
      <FormItem label="账号">
        <Input v-model="params.userAccount" placeholder="请输入账号/身份证号"/>
      </FormItem>
      <FormItem label="姓名">
        <Input v-model="params.userName" placeholder="请输入姓名"/>
      </FormItem>
      <FormItem label="手机号码">
        <Input v-model="params.phone" placeholder="请输入手机号码"/>
      </FormItem>
      <FormItem label="所属部门">
        <Input v-model="params.deptNames" placeholder="请输入所属部门"/>
      </FormItem>
      <FormItem :label-width="0">
        <Button
          type="primary"
          @click="publicGetData"
          v-auth="'列表'"
          style="margin-right: 10px"
        >搜索
        </Button>
        <Button
          type="primary"
          v-auth="'列表'"
          @click="isOpenAdvancedDialog=true"
          style="margin-right: 10px"
        >高级查询
        </Button>
        <Button v-auth="'新增'" type="primary" @click="publicUpdateData">新增</Button>
        <Button type="primary" style="margin-left: 10px;" @click="exportData"  v-auth="'导出'">导出</Button>
        <BaseImport
        v-auth="'导入'"
        :action="action.importUser"
        @onSuccess="handleSuccess"
        :templateName="templateName"
        :dowmTempName="uploadFileName">
        </BaseImport>
        <Button
          type="primary"
          v-auth="'默认角色'"
          @click="DefaultRole"
          style="margin-left: 10px"
        >绑定默认角色
        </Button>
      </FormItem>
    </Form>
    <Breadcrumb></Breadcrumb>
    <!-- <BaseTable
      ref="baseTable"
      :action="action.readUserByPage"
      :columns="columns"
      :menu-code="menuCode"
      :selectList="selectList"
      :public-btn="['delete', 'update', 'reset']"
      @handleRemove="publicRemoveData"
      @handleUpdate="publicUpdateData"
      @handleView="publicUpdateData"
      @handleReset="handleReset"
      @handleClickDrop="handleClickDrop"
    ></BaseTable> -->
    <BaseList
    ref="baseTable"
    :action="action.readUserByPage"
    :columns="columns"
    :tableItem="tableItem"
    :menu-code="menuCode"
    :public-btn="['delete', 'update', 'reset', 'view']"
    @handleView="publicUpdateData"
    @handleRemove="publicRemoveData"
    @handleUpdate="publicUpdateData"
    @handleReset="handleReset"
    @handleClickDrop="handleClickDrop"
    ></BaseList>
    <Drawer
      :title="viewParams.title"
      v-model="viewParams.flag"
      :width="40"
      draggable
      @on-visible-change="publicVisibleChange"
    >
      <UserManageUpdate
        :type="type"
        @closeView="publicCloseView"
        :role-list="roleList"
        :unit-list="unitList"
        :key="isRefreshView"
        :idName="idName"
        :moduleId="id"
      />
    </Drawer>
    <Modal
      v-model="isOpenAdvancedDialog"
      width="600"
      footer-hide
      title="高级查询">
      <AdvancedQuery :keywordsList="advancedQueryColumns" @advancedSearchMethod="advancedSearchMethod"/>
    </Modal>
  </div>
</template>

<script>
import API_KEY from '../../../api'
import { listMixin } from '../../../mixin/minxiList'
import { updateUserStatus, resetPass, exportUser, defaultIdentity } from '../../../api/modules/user/user'
import { getRoleSelect } from '../../../api/modules/user/role'
import { getUnitSelect } from '../../../api/modules/user/unit'
import message from '../../../utils/message'
import BaseUtil from '../../../utils/BaseUtil'
import { tableItem, columns } from './user-columns'

export default {
  name: 'UserManage',
  mixins: [listMixin],
  data () {
    return {
      params: {
        userAccount: '',
        userName: '',
        phone: '',
        deptNames: ''
      },
      action: {
        // 根据分页参数获取表格数据接口（查询表格数据只需要readMenuByPage参数和columns参数）
        readUserByPage: API_KEY.user.readUserByPage,
        removeDataByKey: API_KEY.user.deleteUserByKey,
        importUser: API_KEY.user.importUser
      },
      columns,
      tableItem,
      roleList: [],
      roleIdList: [],
      unitList: [],
      id: '',
      menuCode: 'account-user',
      selectList: ['冻结', '激活', '待审批', '审批不通过'],
      idName: 'id',
      isOpenAdvancedDialog: false,
      advancedQueryColumns: [{
        fieldName: 'au.user_account',
        label: '账号'
      }, {
        fieldName: 'au.user_name',
        label: '姓名'
      }, {
        fieldName: 'sd.dept_names',
        label: '部门名称'
      }, {
        fieldName: 'so.org_names',
        label: '单位名称'
      }, {
        fieldName: 'sr.role_names',
        label: '角色名称'
      }, {
        fieldName: 'aui.phone',
        label: '手机号码'
      }, {
        fieldName: 'aui.sex',
        label: '性别',
        fieldType: 'int',
        itemMap:
            {
              0: '默认',
              1: '男',
              2: '女'
            }
      }, {
        fieldName: 'au.active_status',
        label: '激活状态',
        fieldType: 'int',
        itemMap:
          {
            0: '禁用',
            1: '激活',
            2: '待审核',
            3: '锁定'
          }
      }],
      templateName: 'AccountUser.xlsx',
      downTempName: '用户信息.xlsx',
      uploadFileName: '用户信息模板.xlsx',
      suffix: '用户信息'
    }
  },
  created () {
    this.privateInit()
  },
  methods: {
    /**
       * 重置
       */
    handleReset (row) {
      resetPass(row.id).then(data => {
        message.message.success(data.message)
      })
    },
    /**
       * 点击下拉菜单触发
       * @param name
       * @param row
       */
    handleClickDrop (name, row) {
      updateUserStatus(row.id, name).then((data) => {
        message.message.success(data.message)
        this.$refs.baseTable.getData()
      })
    },
    /**
       * 可用作初始
       */
    privateInit () {
      getRoleSelect().then(({ data }) => {
        this.roleList = data
      })
      getUnitSelect().then(({ data }) => {
        this.unitList = data
      })
    },
    advancedSearchMethod (advancedQueryItemList) {
      this.publicAdvancedQueryData({ advancedQueryItemList })
      this.advancedQueryItemList = advancedQueryItemList
    },
    /**
     * 用户信息记录导出
     */
    exportData () {
      exportUser(this.params).then(res => {
        message.message.success(res.message)
        BaseUtil.downFile(res.data, this.downTempName)
      })
    },
    /**
     * 导入
     */
    handleSuccess (val) {
      this.$refs.baseTable.getData()
    },
    /**
     * 添加默认角色
     */
    DefaultRole () {
      defaultIdentity().then(res => {
        message.message.success(res.message)
      })
    }
  },
  components: {
    UserManageUpdate: () => import('./UserManageUpdate'),
    AdvancedQuery: () => import('../../../components/view-ui/AdvancedQuery'),
    BaseImport: () => import('../../../components/view-ui/BaseImport')
  }
}
</script>

<style scoped>

</style>
